<?php

/**
 * sfGuardUser form base class.
 *
 * @package    ##PROJECT_NAME##
 * @subpackage form
 * @author     ##AUTHOR_NAME##
 * @version    SVN: $Id: sfPropelFormGeneratedTemplate.php 16976 2009-04-04 12:47:44Z fabien $
 */
class BasesfGuardUserForm extends BaseFormPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'                            => new sfWidgetFormInputHidden(),
      'username'                      => new sfWidgetFormInput(),
      'nickname'                      => new sfWidgetFormInput(),
      'algorithm'                     => new sfWidgetFormInput(),
      'salt'                          => new sfWidgetFormInput(),
      'password'                      => new sfWidgetFormInput(),
      'created_at'                    => new sfWidgetFormDateTime(),
      'last_login'                    => new sfWidgetFormDateTime(),
      'is_active'                     => new sfWidgetFormInputCheckbox(),
      'is_super_admin'                => new sfWidgetFormInputCheckbox(),
      'email'                         => new sfWidgetFormInput(),
      'gender'                        => new sfWidgetFormInput(),
      'account'                       => new sfWidgetFormInput(),
      'rating'                        => new sfWidgetFormInput(),
      'see'                           => new sfWidgetFormInput(),
      'photo'                         => new sfWidgetFormInput(),
      'birthday'                      => new sfWidgetFormDate(),
      'phone'                         => new sfWidgetFormInput(),
      'adres'                         => new sfWidgetFormInput(),
      'skype'                         => new sfWidgetFormInput(),
      'icq'                           => new sfWidgetFormInput(),
      'is_top'                        => new sfWidgetFormInputCheckbox(),
      'is_vip'                        => new sfWidgetFormInputCheckbox(),
      'is_abon'                       => new sfWidgetFormInputCheckbox(),
      'is_marital'                    => new sfWidgetFormInput(),
      'language'                      => new sfWidgetFormInput(),
      'have_child'                    => new sfWidgetFormInputCheckbox(),
      'old_partner'                   => new sfWidgetFormInput(),
      'have_child_partner'            => new sfWidgetFormInputCheckbox(),
      'country'                       => new sfWidgetFormInput(),
      'have_photos'                   => new sfWidgetFormInputCheckbox(),
      'have_video'                    => new sfWidgetFormInputCheckbox(),
      'have_new_message'              => new sfWidgetFormInputCheckbox(),
      'have_new_interes'              => new sfWidgetFormInputCheckbox(),
      'have_new_fav'                  => new sfWidgetFormInputCheckbox(),
      'is_otpusk'                     => new sfWidgetFormInputCheckbox(),
      'date_expire_abon'              => new sfWidgetFormDate(),
      'date_expire_otpusk'            => new sfWidgetFormDate(),
      'city'                          => new sfWidgetFormInput(),
      'zip'                           => new sfWidgetFormInput(),
      'time'                          => new sfWidgetFormInput(),
      'block'                         => new sfWidgetFormInputCheckbox(),
      'sesid'                         => new sfWidgetFormInput(),
      'is_online'                     => new sfWidgetFormInputCheckbox(),
      'eye_color'                     => new sfWidgetFormInput(),
      'hair_lenght'                   => new sfWidgetFormInput(),
      'hair_color'                    => new sfWidgetFormInput(),
      'hair_type'                     => new sfWidgetFormInput(),
      'education'                     => new sfWidgetFormInput(),
      'religion'                      => new sfWidgetFormInput(),
      'know_lang'                     => new sfWidgetFormInput(),
      'my_read'                       => new sfWidgetFormInput(),
      'my_musik'                      => new sfWidgetFormInput(),
      'my_rest'                       => new sfWidgetFormInput(),
      'my_food'                       => new sfWidgetFormInput(),
      'my_sport'                      => new sfWidgetFormInput(),
      'my_harakter'                   => new sfWidgetFormInput(),
      'partner_age_from'              => new sfWidgetFormInput(),
      'partner_age_to'                => new sfWidgetFormInput(),
      'partner_height_from'           => new sfWidgetFormInput(),
      'partner_height_to'             => new sfWidgetFormInput(),
      'height'                        => new sfWidgetFormInput(),
      'ves'                           => new sfWidgetFormInput(),
      'profession'                    => new sfWidgetFormInput(),
      'is_photo'                      => new sfWidgetFormInputCheckbox(),
      'is_video'                      => new sfWidgetFormInputCheckbox(),
      'is_partner'                    => new sfWidgetFormInputCheckbox(),
      'partner_id'                    => new sfWidgetFormPropelChoice(array('model' => 'sfGuardUser', 'add_empty' => true)),
      'new_message'                   => new sfWidgetFormInputCheckbox(),
      'new_fav'                       => new sfWidgetFormInputCheckbox(),
      'new_interest'                  => new sfWidgetFormInputCheckbox(),
      'new_gift'                      => new sfWidgetFormInputCheckbox(),
      'about_me'                      => new sfWidgetFormTextarea(),
      'about_partner'                 => new sfWidgetFormTextarea(),
      'about_hobby'                   => new sfWidgetFormTextarea(),
      'age'                           => new sfWidgetFormInput(),
      'introduction_letter'           => new sfWidgetFormTextarea(),
      'zodiac'                        => new sfWidgetFormInput(),
      'astrology_sign'                => new sfWidgetFormInput(),
      'drinking'                      => new sfWidgetFormInputCheckbox(),
      'smoking'                       => new sfWidgetFormInputCheckbox(),
      'wants_children'                => new sfWidgetFormInputCheckbox(),
      'best_time_of_watch'            => new sfWidgetFormTextarea(),
      'contact_face'                  => new sfWidgetFormInput(),
      'mobile_phone'                  => new sfWidgetFormInput(),
      'count_user'                    => new sfWidgetFormInput(),
      'bank_information'              => new sfWidgetFormTextarea(),
      'custom_file1'                  => new sfWidgetFormInput(),
      'custom_file2'                  => new sfWidgetFormInput(),
      'custom_file3'                  => new sfWidgetFormInput(),
      'first_name'                    => new sfWidgetFormInput(),
      'last_name'                     => new sfWidgetFormInput(),
      'full_profile'                  => new sfWidgetFormInputCheckbox(),
      'have_chanel'                   => new sfWidgetFormInputCheckbox(),
      'sf_guard_user_group_list'      => new sfWidgetFormPropelChoiceMany(array('model' => 'sfGuardGroup')),
      'sf_guard_user_permission_list' => new sfWidgetFormPropelChoiceMany(array('model' => 'sfGuardPermission')),
    ));

    $this->setValidators(array(
      'id'                            => new sfValidatorPropelChoice(array('model' => 'sfGuardUser', 'column' => 'id', 'required' => false)),
      'username'                      => new sfValidatorString(array('max_length' => 128)),
      'nickname'                      => new sfValidatorString(array('max_length' => 250)),
      'algorithm'                     => new sfValidatorString(array('max_length' => 128)),
      'salt'                          => new sfValidatorString(array('max_length' => 128)),
      'password'                      => new sfValidatorString(array('max_length' => 128)),
      'created_at'                    => new sfValidatorDateTime(array('required' => false)),
      'last_login'                    => new sfValidatorDateTime(array('required' => false)),
      'is_active'                     => new sfValidatorBoolean(),
      'is_super_admin'                => new sfValidatorBoolean(),
      'email'                         => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'gender'                        => new sfValidatorString(array('max_length' => 3, 'required' => false)),
      'account'                       => new sfValidatorNumber(array('required' => false)),
      'rating'                        => new sfValidatorInteger(array('required' => false)),
      'see'                           => new sfValidatorInteger(array('required' => false)),
      'photo'                         => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'birthday'                      => new sfValidatorDate(array('required' => false)),
      'phone'                         => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'adres'                         => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'skype'                         => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'icq'                           => new sfValidatorString(array('max_length' => 50, 'required' => false)),
      'is_top'                        => new sfValidatorBoolean(array('required' => false)),
      'is_vip'                        => new sfValidatorBoolean(array('required' => false)),
      'is_abon'                       => new sfValidatorBoolean(array('required' => false)),
      'is_marital'                    => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'language'                      => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'have_child'                    => new sfValidatorBoolean(array('required' => false)),
      'old_partner'                   => new sfValidatorInteger(array('required' => false)),
      'have_child_partner'            => new sfValidatorBoolean(array('required' => false)),
      'country'                       => new sfValidatorString(array('max_length' => 10)),
      'have_photos'                   => new sfValidatorBoolean(array('required' => false)),
      'have_video'                    => new sfValidatorBoolean(array('required' => false)),
      'have_new_message'              => new sfValidatorBoolean(array('required' => false)),
      'have_new_interes'              => new sfValidatorBoolean(array('required' => false)),
      'have_new_fav'                  => new sfValidatorBoolean(array('required' => false)),
      'is_otpusk'                     => new sfValidatorBoolean(array('required' => false)),
      'date_expire_abon'              => new sfValidatorDate(array('required' => false)),
      'date_expire_otpusk'            => new sfValidatorDate(array('required' => false)),
      'city'                          => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'zip'                           => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'time'                          => new sfValidatorInteger(array('required' => false)),
      'block'                         => new sfValidatorBoolean(),
      'sesid'                         => new sfValidatorString(array('max_length' => 250, 'required' => false)),
      'is_online'                     => new sfValidatorBoolean(),
      'eye_color'                     => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'hair_lenght'                   => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'hair_color'                    => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'hair_type'                     => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'education'                     => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'religion'                      => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'know_lang'                     => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'my_read'                       => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'my_musik'                      => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'my_rest'                       => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'my_food'                       => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'my_sport'                      => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'my_harakter'                   => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'partner_age_from'              => new sfValidatorInteger(array('required' => false)),
      'partner_age_to'                => new sfValidatorInteger(array('required' => false)),
      'partner_height_from'           => new sfValidatorInteger(array('required' => false)),
      'partner_height_to'             => new sfValidatorInteger(array('required' => false)),
      'height'                        => new sfValidatorInteger(array('required' => false)),
      'ves'                           => new sfValidatorInteger(array('required' => false)),
      'profession'                    => new sfValidatorString(array('max_length' => 250, 'required' => false)),
      'is_photo'                      => new sfValidatorBoolean(array('required' => false)),
      'is_video'                      => new sfValidatorBoolean(array('required' => false)),
      'is_partner'                    => new sfValidatorBoolean(array('required' => false)),
      'partner_id'                    => new sfValidatorPropelChoice(array('model' => 'sfGuardUser', 'column' => 'id', 'required' => false)),
      'new_message'                   => new sfValidatorBoolean(array('required' => false)),
      'new_fav'                       => new sfValidatorBoolean(array('required' => false)),
      'new_interest'                  => new sfValidatorBoolean(array('required' => false)),
      'new_gift'                      => new sfValidatorBoolean(array('required' => false)),
      'about_me'                      => new sfValidatorString(array('required' => false)),
      'about_partner'                 => new sfValidatorString(array('required' => false)),
      'about_hobby'                   => new sfValidatorString(array('required' => false)),
      'age'                           => new sfValidatorInteger(array('required' => false)),
      'introduction_letter'           => new sfValidatorString(array('required' => false)),
      'zodiac'                        => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'astrology_sign'                => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'drinking'                      => new sfValidatorBoolean(array('required' => false)),
      'smoking'                       => new sfValidatorBoolean(array('required' => false)),
      'wants_children'                => new sfValidatorBoolean(array('required' => false)),
      'best_time_of_watch'            => new sfValidatorString(array('required' => false)),
      'contact_face'                  => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'mobile_phone'                  => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'count_user'                    => new sfValidatorInteger(array('required' => false)),
      'bank_information'              => new sfValidatorString(array('required' => false)),
      'custom_file1'                  => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'custom_file2'                  => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'custom_file3'                  => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'first_name'                    => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'last_name'                     => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'full_profile'                  => new sfValidatorBoolean(array('required' => false)),
      'have_chanel'                   => new sfValidatorBoolean(array('required' => false)),
      'sf_guard_user_group_list'      => new sfValidatorPropelChoiceMany(array('model' => 'sfGuardGroup', 'required' => false)),
      'sf_guard_user_permission_list' => new sfValidatorPropelChoiceMany(array('model' => 'sfGuardPermission', 'required' => false)),
    ));

    $this->validatorSchema->setPostValidator(
      new sfValidatorPropelUnique(array('model' => 'sfGuardUser', 'column' => array('username')))
    );

    $this->widgetSchema->setNameFormat('sf_guard_user[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function getModelName()
  {
    return 'sfGuardUser';
  }

  public function getI18nModelName()
  {
    return 'sfGuardUserI18n';
  }

  public function getI18nFormClass()
  {
    return 'sfGuardUserI18nForm';
  }

  public function updateDefaultsFromObject()
  {
    parent::updateDefaultsFromObject();

    if (isset($this->widgetSchema['sf_guard_user_group_list']))
    {
      $values = array();
      foreach ($this->object->getsfGuardUserGroups() as $obj)
      {
        $values[] = $obj->getGroupId();
      }

      $this->setDefault('sf_guard_user_group_list', $values);
    }

    if (isset($this->widgetSchema['sf_guard_user_permission_list']))
    {
      $values = array();
      foreach ($this->object->getsfGuardUserPermissions() as $obj)
      {
        $values[] = $obj->getPermissionId();
      }

      $this->setDefault('sf_guard_user_permission_list', $values);
    }

  }

  protected function doSave($con = null)
  {
    parent::doSave($con);

    $this->savesfGuardUserGroupList($con);
    $this->savesfGuardUserPermissionList($con);
  }

  public function savesfGuardUserGroupList($con = null)
  {
    if (!$this->isValid())
    {
      throw $this->getErrorSchema();
    }

    if (!isset($this->widgetSchema['sf_guard_user_group_list']))
    {
      // somebody has unset this widget
      return;
    }

    if (is_null($con))
    {
      $con = $this->getConnection();
    }

    $c = new Criteria();
    $c->add(sfGuardUserGroupPeer::USER_ID, $this->object->getPrimaryKey());
    sfGuardUserGroupPeer::doDelete($c, $con);

    $values = $this->getValue('sf_guard_user_group_list');
    if (is_array($values))
    {
      foreach ($values as $value)
      {
        $obj = new sfGuardUserGroup();
        $obj->setUserId($this->object->getPrimaryKey());
        $obj->setGroupId($value);
        $obj->save();
      }
    }
  }

  public function savesfGuardUserPermissionList($con = null)
  {
    if (!$this->isValid())
    {
      throw $this->getErrorSchema();
    }

    if (!isset($this->widgetSchema['sf_guard_user_permission_list']))
    {
      // somebody has unset this widget
      return;
    }

    if (is_null($con))
    {
      $con = $this->getConnection();
    }

    $c = new Criteria();
    $c->add(sfGuardUserPermissionPeer::USER_ID, $this->object->getPrimaryKey());
    sfGuardUserPermissionPeer::doDelete($c, $con);

    $values = $this->getValue('sf_guard_user_permission_list');
    if (is_array($values))
    {
      foreach ($values as $value)
      {
        $obj = new sfGuardUserPermission();
        $obj->setUserId($this->object->getPrimaryKey());
        $obj->setPermissionId($value);
        $obj->save();
      }
    }
  }

}
